<template>
  <div>
    <el-card>
      <!-- 用户列表区域 -->
      <el-table :data="orderList" border stripe>
        <el-table-column type="index"></el-table-column>
        <el-table-column label="姓名" prop="userid"></el-table-column>
        <el-table-column label="订单号" prop="orderid"></el-table-column>
        <el-table-column label="收货地址" prop="address"></el-table-column>
        <el-table-column label="购买时间" prop="salestime"></el-table-column>
        <el-table-column label="付款金额" prop="sumprice"></el-table-column>
        <el-table-column label="订单状态" prop="status">
            <template scope="scope">  
                    <el-tag type="danger" v-if="scope.row.status=='1'" size="mini">油库处理中</el-tag>
                    <el-tag type="warning" v-if="scope.row.status=='2'" size="mini">正在路上</el-tag>
                    <el-tag type="info" v-if="scope.row.status=='3'" size="mini">已收货</el-tag>                               
                </template>
        </el-table-column>
        <el-table-column label="操作" width="180px">
          <template slot-scope="scope">
            <!-- 修改按钮 -->
            <el-button type="primary" icon="el-icon-edit" size="mini" @click="certainGetOil(scope.row.orderid)">确认收货</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
export default {
  data () {
    return {
      orderList: []
    }
  },
  created(){
    this.getOrderList()
  },
  methods: {
    async getOrderList() {
      let userInfo = {username: window.sessionStorage.getItem('username')}
      const {data: res} = await this.$http.get('sysservice/order/userGetOrder', {
        params: userInfo
      })
      this.orderList = res.data.item
    },
    async certainGetOil(orderId) {
      let orderInfo = {orderid: orderId}     
      const { data: res } = await this.$http.get('sysservice/order/updateStatus', {
        params: orderInfo
      })
      console.log(res);
      
      if (res.code !== 2000) {
            this.$message.error('确认失败！')
          }

      this.$message.success('收货成功！')
      this.getOrderList()
      
    }

  }
}
</script>

<style scoped lang="less">

</style>